import { Component } from 'vue'
import { createRouter, createWebHistory } from "vue-router"

const routes: { path: string, component: Component }[] = []
let loadedModules = import.meta.glob('./pages/**/*.vue', { eager: true }) as Record<string, { default: Component }>
let componentModuleList = Object.entries(loadedModules)
componentModuleList.forEach(([filePath, componentConfig]) => {
    let path = filePath.replace(/^\.\/pages/, '').replace(/\.vue$/, '').replace(/\/Index/, '/')
    routes.push({ path, component: componentConfig.default })
})

const router = createRouter({
    history: createWebHistory(),
    routes
})

export default router